window.onload = function () {
	let token = sessionStorage.getItem('token')
	let id = sessionStorage.getItem('id')
	let name = sessionStorage.getItem('name')
	let day_time = sessionStorage.getItem('day_time')
	let show_id = sessionStorage.getItem('show_id')
	let leftName = document.querySelector('.leftName')
	let twoImg = document.querySelector('#twoImg')
	let timeSpan = document.querySelector('#timeSpan')
	let timeSpanTwo = document.querySelector('#timeSpanTwo')
	console.log(token, id, name)
	function downloadIamge(selector, name) {
		// 通过选择器获取img元素
		var img = document.querySelector(selector)
		// 将图片的src属性作为URL地址
		var url = img.src
		var a = document.createElement('a')
		var event = new MouseEvent('click')

		a.download = name || '下载图片名称'
		a.href = url

		a.dispatchEvent(event)
	}
	if (token != null && id != null && name != null) {
		leftName.innerHTML = name
		let url = 'http://newshopapi.0melon0.cn/api/f_user/Qrcode'
		url = `${url}?token=${token}&id=${id}`
		fetch(url, {
			method: 'GET',
		})
			.then(function (data) {
				return data.json()
			})
			.then(function (data) {
				let arr = day_time.slice(5).split('-')
				console.log(arr)
				timeSpan.innerHTML = `${arr[0]}月${arr[1]}日${show_id}`
				timeSpanTwo.innerHTML = day_time.slice(0, 4)
				twoImg.src = data.data.data
				let btn = document.querySelector('.btn')
				btn.addEventListener('click', function () {
					downloadIamge('#twoImg', '二维码')
					location.href = '../查看预约页/index.html'
				})
			})
	} else {
		alert('请先选择场次')
		location.href = '../预约页/index.html'
	}
}
